#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class Solution
{
public:
    int maxProduct(vector<int> &nums)
    {
        int Max = INT32_MIN;
        int iMax = 1;
        int iMin = 1;
        for (int i = 0; i < nums.size(); i++)
        {
            if (nums[i] < 0)
            {
                int tmp = iMax;
                iMax = iMin;
                iMin = tmp;
            }
            iMax = max(iMax * nums[i], nums[i]);
            iMin = min(iMin * nums[i], nums[i]);
            Max = max(Max, iMax);
        }
        return Max;
    }
};